from owlready2 import *

from owlready2 import *

onto = get_ontology("http://test.org/onto.owl")

with onto:
    class Drug(Thing):
        # 添加python方法到OWL对象, python_module
        def get_per_tablet_cost(self):
            return self.cost / self.number_of_tablets

    class has_for_cost(Drug >> float, FunctionalProperty):
        python_name = "cost"

    class has_for_number_of_tablets(Drug >> int, FunctionalProperty):
        python_name = "number_of_tablets"

def add_python_method_to_owl_class():
    print('1. add_python_method_to_owl_class')
    my_drug = Drug(cost = 10.0, number_of_tablets = 5)
    print('\tmy_drug.get_per_tablet_cost()', my_drug.get_per_tablet_cost())

def forward_declarations():
    print('2. forward_declarations')
    # class has_for_active_principle(Property): pass
    # with onto:
    #     class Drug(Thing): pass
    #     class has_for_active_principle(Drug >> ActivePrinciple): pass
    #     class Drug(Thing): # Extends the previous definition of Drug
    #         is_a = [has_for_active_principle.some(ActivePrinciple)]

add_python_method_to_owl_class()
forward_declarations()


